<?php
/**
 * 我要交流模块
 * @author Jackie Yang
 *
 */
class ctrl_chat extends ctrl_base
{
    public static function index() {
    	$chat_type = isset($_GET['chat_type'])? trim($_GET['chat_type']):'00';
    	self::smarty()->assign('chat_type',$chat_type);
    	self::smarty() -> display('chat.html');
    }
    
    public static function saveUserChat() {
    	//获取open_id 走用户体系取 user_id
    	if(empty($_SESSION['wx_userinfo']['openid'])) {
    		setcookie('backurl',HOST_URL.'/?'.$_SERVER['QUERY_STRING'],0);
    		ctrl_weixin::oauth();
    	}else{
    		setcookie('backurl','');
    		unset($_SESSION['backurl']);
    	}
    	$data = array();
    	$data['User_ID'] = $_SESSION['wx_userinfo']['openid'];
    	$data['User_Company'] = trim($_POST['User_Company']);
    	$data['User_Person'] = trim($_POST['User_Person']);
    	$data['Product_Type'] = trim($_POST['Product_Type']);
    	$data['Product_Spec'] = trim($_POST['Product_Spec']);
    	$data['Product_Grade'] = trim($_POST['Product_Grade']);
    	$data['Chat_Title'] = trim($_POST['Chat_Title']);
    	$data['Chat_Content'] = trim($_POST['Chat_Content']);
    	$data['Chat_Type'] = trim($_POST['Chat_Type']);
    	
    	$result = model_chat::add_chat($data);
    	
    	if ($result != 0) { //处理成功
			self::smarty ()->assign ( "result_class", 'icon67_status' );
			self::smarty ()->assign ( "errMsg", '恭喜您，提交成功！' );
			self::smarty ()->assign ( "comment", '我们将在1个工作日内回复您' );
			self::smarty ()->display ( 'show_result.html' );
			exit ();
		} else {
			self::smarty ()->assign ( "result_class", 'icon67_status warn' );
			self::smarty ()->assign ( "errMsg", '对不起，数据提交失败！' );
			self::smarty ()->assign ( "comment", '系统出现故障，请稍后重试' );
			self::smarty ()->display ( 'show_result.html' );
			exit ();
		}
    }
}
